package com.shiguo365.market.display.adapter;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.shiguo365.market.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by caomenglong on 16/7/7.
 */
public class UserCartAdapter extends RecyclerView.Adapter<UserCartAdapter.ViewHolder> {

    private final static String TAG = "CartAdapter";
    private final Activity mActivity;
    private final LayoutInflater mInflater;
    private final List<JSONObject> objects;

    public UserCartAdapter(@NonNull Activity activity, @NonNull List<JSONObject> objects) {
        this.mActivity = activity;
        mInflater = LayoutInflater.from(activity);
        this.objects = objects;
    }

    @Override
    public int getItemCount() {
        return objects.size();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(mInflater.inflate(R.layout.item_cart, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.update(position);
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        private JSONObject object;

        protected ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @BindView(R.id.cart_item_tv_title)
        protected TextView mTvTitle;

        @BindView(R.id.cart_item_tv_spec)
        protected TextView mTvSpec;

        @BindView(R.id.cart_item_edt_count)
        protected TextView mEdtCount;


        protected void update(int position) {
            object = objects.get(position);


            mTvTitle.setText(object.getString("title"));
            mTvSpec.setText("规格未知");
            mEdtCount.setText("" + object.getString("count"));
//            Glide.with(mActivity).load(product.getString("img")).placeholder(R.drawable.image_placeholder).dontAnimate().into(img);
//            tvTitle.setText(product.getString("title"));
//            tvPrice.setText("￥:" + product.getString("price"));
//            edtCount.setText("" + product.getInteger("count"));
        }
    }
}
